package com.driver.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import com.driver.system.controller.form.*;
import com.driver.system.db.pojo.DriverFineEntity;
import com.driver.system.db.pojo.DriverLockdownEntity;
import com.driver.system.service.DriverFineService;
import com.driver.system.service.DriverLockDownService;
import com.driver.system.util.PageUtils;
import com.driver.system.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 14375
 */
@RestController
@RequestMapping("/driver/lockdown")
@Tag(name = "DriverLockDownController", description = "司机禁止接单Web接口")
public class DriverLockDownController {
    @Resource
    private DriverLockDownService driverLockDownService;

    @PostMapping("/searchDriverLockdownByPage")
    @SaCheckPermission(value = {"ROOT", "DRIVERLOCKDOWN:SELECT"}, mode = SaMode.OR)
    @Operation(summary = "查询禁止接单分页记录")
    public R searchDriverLockdownByPage(@RequestBody @Valid SearchDriverLockDownByPageForm form) {
        int page = form.getPage();
        int length = form.getLength();
        int start = (page - 1) * length;
        Map param = BeanUtil.beanToMap(form);
        param.put("start", start);
        PageUtils pageUtils = driverLockDownService.searchDriverLockdownByPage(param);
        return R.ok().put("result", pageUtils);
    }

    @PostMapping("/searchDriverLockdownById")
    @Operation(summary = "根据ID查找禁止接单司机")
    @SaCheckPermission(value = {"ROOT", "DRIVERLOCKDOWN:SELECT"}, mode = SaMode.OR)
    public R searchDriverLockdownById(@Valid @RequestBody SearchDriverLockDownByIdForm form) {
        HashMap map = driverLockDownService.searchDriverLockdownById(form.getLockdownId());
        return R.ok().put("result", map);
    }

    @PostMapping("/insertDriverLockdown")
    @Operation(summary = "添加禁止接单司机信息")
    public R insertDriverLockdown(@RequestBody @Valid InsertDriverLockDownForm form){
        DriverLockdownEntity driverLockdown = BeanUtil.toBean(form, DriverLockdownEntity.class);
        int rows = driverLockDownService.insertDriverLockdown(driverLockdown);
        return R.ok().put("rows", rows);
    }

    @PostMapping("/updateDriverLockdown")
    @SaCheckPermission(value = {"ROOT", "DRIVERLOCKDOWN:UPDATE"}, mode = SaMode.OR)
    @Operation(summary = "修改禁止接单司机信息")
    public R updateDriverLockdown(@Valid @RequestBody UpdateDriverLockDownForm form) {
        Map param = BeanUtil.beanToMap(form);
        int rows = driverLockDownService.updateDriverLockdown(param);
        return R.ok().put("rows", rows);
    }

    @PostMapping("/deleteDriverLockdownByIds")
    @SaCheckPermission(value = {"ROOT", "DRIVERLOCKDOWN:DELETE"}, mode = SaMode.OR)
    @Operation(summary = "批量删除禁止接单司机信息")
    public R deleteDriverLockdownByIds(@Valid @RequestBody DeleteDriverLockDownByIdsForm form) {
        int rows = driverLockDownService.deleteDriverLockdownByIds(form.getIds());
        return R.ok().put("rows", rows);
    }
}
